<?php
header('Content-Type: text/html; charset=UTF-8');

require 'database.php';
$db = new DB();

$Qry = 'SELECT id, name, url
		FROM cat
		WHERE url LIKE "%+%"
		ORDER BY name ASC';
$res = $db->fetchAll($Qry);

$search = array('+', '_', ' ', "'", '"');

echo '<ul>';
foreach ($res as $key=>$value) {

	$tag = str_replace($search, '-', $value['url']);
	$tag = str_replace('%27', '', $tag);
	$tag = trim($tag, '-');

// 	$query = 'UPDATE cat SET tag = "' . $tag . '" WHERE id = ' . $value['id'];
// 	$db->Query($query);

	echo '<li>' . ($key + 1) . ' - <a href="fix-tag.php?url=' . urlencode($value['url']) . '&tag=' . $tag . '" target="_blank">' . $value['name'] . '</a></li>';
}
echo '</ul>';